import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

//因为接收端不知道发送端什么时候停止发送，故采用死循环接收
public class UDP_receive_Demo {
    public static void main(String[] args) throws IOException {
        DatagramSocket datagramSocket = new DatagramSocket(15000);
        while(true){
            byte[] bys = new byte[1024];
            DatagramPacket datagramPacket = new DatagramPacket(bys,bys.length);
            datagramSocket.receive(datagramPacket);
            byte[] data = datagramPacket.getData();
            int len = data.length;
            System.out.println(new String(data,0,len));
        }
    }
}
